<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:p="http://primefaces.org/ui">
    <ui:composition 
        template="/resources/template/template.xhtml">

        <ui:define name="content">

            <h:panelGroup rendered="#{!webUserController.hasPrivilege('LabSampleCollecting')}" >
                You are NOT authorized
            </h:panelGroup>

            <h:panelGroup rendered="#{webUserController.hasPrivilege('LabSampleCollecting')}" >

                <h:form  >

                    <p:growl />




                    <p:panel header="Sample" >

                        <h:panelGrid columns="2" styleClass="alignTop" >
                            <h:panelGroup >
                                <h:panelGrid columns="2">
                                    <h:outputLabel value="From"/>
                                    <p:calendar id="fromDate" value="#{patientInvestigationController.fromDate}" navigator="true" pattern="dd MMMM yy - hh:mm a" >
                                        <f:ajax event="dateSelect" execute="sample"  render="sample toDate fromDate"/>
                                    </p:calendar>
                                    <h:outputLabel value="To"/>
                                    <p:calendar id="toDate" value="#{patientInvestigationController.toDate}" navigator="true" pattern="dd MMMM yy - hh:mm a" >
                                        <f:ajax event="dateSelect" execute="sample"  render="sample toDate fromDate"/>
                                    </p:calendar>

                                    <p:defaultCommand target="btnRefresh"/>

                                    <p:commandButton id="btnRefresh" ajax="false" 
                                                     actionListener="#{patientInvestigationController.prepareToSample()}" 
                                                     value="List to Collect" onclick="onSubmitButton();"  >
                                    </p:commandButton>


                                    <p:spacer ></p:spacer>
                                    <p:commandButton id="btnCollected" ajax="false" 
                                                     actionListener="#{patientInvestigationController.prepareSampled()}" 
                                                     value="List Collected" onclick="onSubmitButton();"  >
                                    </p:commandButton>
                                    <p:spacer ></p:spacer>
                                    <p:commandButton value="Barcode Printing" ajax="false" action="sampling" ></p:commandButton>

                                </h:panelGrid>
                            </h:panelGroup>
                            <h:panelGroup >


                                <table >
                                    <tr>
                                        <th>
                                            <p:outputLabel value="Patient" ></p:outputLabel>
                                        </th>
                                        <th>

                                        </th>
                                    </tr>
                                    <ui:repeat value="#{patientInvestigationController.lstToSamle}" var="s" >
                                    </ui:repeat>
                                </table>

                                <p:dataTable  
                                    id="sample" 
                                    value="#{patientInvestigationController.lstToSamle}" 
                                    var="smpIx" 
                                    paginator="#{patientInvestigationController.showSamplingPagination}"
                                    paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                    rowsPerPageTemplate="10,25,50"
                                    >
                                    <p:column headerText="Bill No" width="100">
                                        <p:outputLabel value="#{smpIx.billItem.bill.insId}" styleClass="#{smpIx.billItem.bill.cancelled or smpIx.billItem.transRefund ? 'redtext':''}"/>
                                    </p:column>
                                    <p:column headerText="Patient" >
                                        <h:outputLabel value="#{smpIx.billItem.bill.patient.person.nameWithTitle}" styleClass="#{smpIx.billItem.bill.cancelled or smpIx.billItem.transRefund ? 'redtext':''}"/>
                                    </p:column>
                                    <p:column headerText="Investigation" >
                                        <h:outputLabel value="#{smpIx.investigation.name}" styleClass="#{smpIx.billItem.bill.cancelled or smpIx.billItem.transRefund ? 'redtext':''}"/>
                                    </p:column>
                                    <p:column headerText="Sample Details">
                                        <p:selectBooleanCheckbox disabled="#{smpIx.collected}" id="chkSampledOutside" value="#{smpIx.sampleOutside}"  itemLabel="Outside" >
                                            <f:ajax render="calSampledDate institution" event="change" execute="chkSampledOutside"/>
                                        </p:selectBooleanCheckbox>

                                        <p:calendar rendered="#{!smpIx.collected}" disabled="#{!smpIx.sampleOutside}"  id="calSampledDate" pattern="dd/MMM/yyyy - hh:mm:ss a" 
                                                    value="#{patientInvestigationController.sampledOutsideDate}" ></p:calendar>
                                        <h:outputLabel rendered="#{smpIx.collected}"  id="lblSampledDate" value="#{smpIx.sampledAt}" >
                                            <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm a"  />
                                        </h:outputLabel>

                                        <p:autoComplete  forceSelection="true" value="#{smpIx.sampleInstitution}" placeholder="Collected Institution"
                                                         completeMethod="#{institutionController.completeIns}" id="institution"
                                                         rendered="#{!smpIx.collected}" disabled="#{!smpIx.sampleOutside}"  
                                                         var="ix" itemLabel="#{ix.name}" itemValue="#{ix}" size="30"  >
                                        </p:autoComplete>



                                    </p:column>
                                    <p:column headerText="Actions">


                                        <h:panelGrid columns="3" >
                                            <p:commandButton  disabled="#{smpIx.collected or smpIx.billItem.bill.cancelled eq true or smpIx.billItem.transRefund eq true}"   
                                                              id="btnSample" value="Collect" action="#{patientInvestigationController.markAsSampled()}" 
                                                              process="chkSampledOutside calSampledDate btnSample" update="@all"
                                                              >
                                                <f:setPropertyActionListener value="#{smpIx}" target="#{patientInvestigationController.current}"></f:setPropertyActionListener>
                                            </p:commandButton>
                                            <p:commandButton  disabled="#{!smpIx.collected or smpIx.billItem.transRefund}"   id="btnSampleRevert" value="Revert" 
                                                              action="#{patientInvestigationController.revertMarkedSample()}" 
                                                              process="chkSampledOutside calSampledDate btnSampleRevert" update="@all">
                                                <f:setPropertyActionListener value="#{smpIx}" target="#{patientInvestigationController.current}"></f:setPropertyActionListener>
                                            </p:commandButton>
                                            <p:commandButton  disabled="#{!smpIx.collected}"   id="btnPrint" value="Print" 
                                                              ajax="false">
                                                <p:printer target="stickerPrint" ></p:printer>
                                            </p:commandButton>

                                        </h:panelGrid>
                                        <div class="printBlock">
                                            <h:panelGroup id="stickerPrint" >
                                                <div class="stickerLabel" style="height:98%; width: 98%;border: 1px solid red;">
                                                    <div style="width: 100%;">
                                                        <p:barcode cache="false" value="#{smpIx.patient.phn}" type="code128" style="width: 100%; height: 80%;" ></p:barcode>
                                                    </div>
                                                    <div>
                                                        <h:outputLabel value="#{smpIx.patient.person.nameWithTitle}" style="font-size: 8pt;" ></h:outputLabel>
                                                    </div>
                                                    <div>
                                                        <ui:repeat value="#{smpIx.billItem.bill.billItems}" var="billc" >
                                                            |
                                                            <h:outputLabel value="#{billc.item.name}" style="font-size: 8pt;" ></h:outputLabel>
                                                            |
                                                        </ui:repeat>
                                                    </div>
                                                </div>
                                            </h:panelGroup>
                                        </div>
                                    </p:column>
                                </p:dataTable>

                            </h:panelGroup>
                        </h:panelGrid>




                    </p:panel>



                </h:form>


            </h:panelGroup>

        </ui:define>

    </ui:composition>

</html>